﻿using Entity;
using System.ComponentModel;
using DAO;
using System;
using System.Text;
using System.Security.Cryptography;

namespace BUS
{
    public class NguoiDungBUS
    {
        public string EncodePassword(string originalPassword)
        {
            Byte[] originalBytes;
            Byte[] encodedBytes;
            MD5 md5;
            md5 = new MD5CryptoServiceProvider();
            originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
            encodedBytes = md5.ComputeHash(originalBytes);
            return BitConverter.ToString(encodedBytes);
        }

        public BindingList<NguoiDung> LoadAll()
        {

            NguoiDungDAO d = new NguoiDungDAO();
            return d.LoadAll();
        }
        public NguoiDung LoadByID(int id)
        {
            NguoiDungDAO d = new NguoiDungDAO();
            return d.LoadByID(id);
        }
        public int DeleteByStringId(int id)
        {
            NguoiDungDAO d = new NguoiDungDAO();

            return d.DeleteByStringId(id);
        }
        public NguoiDung Login(string tendangnhap, string matkhau)
        {
           // matkhau = EncodePassword(matkhau);
            NguoiDungDAO d = new NguoiDungDAO();
            return d.Login(tendangnhap, matkhau);
        }
        public int Insert(NguoiDung kv)
        {
            //kv.MatKhau = EncodePassword(kv.MatKhau);
            NguoiDungDAO d = new NguoiDungDAO();
            return d.Insert(kv);
        }
        public int Update(NguoiDung kv)
        {
            //kv.MatKhau = EncodePassword(kv.MatKhau);
            NguoiDungDAO d = new NguoiDungDAO();
            return d.Update(kv);
        }
    }
}
